package charpter11.lynx;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.TreeSet;

public class Four {
	private static Collection<String> fill(Collection<String> collection){
		long begin = System.currentTimeMillis();
		for (int i = 0; i < 10; i++){
			collection.add(MovieGenerator.next());
		}
		long end = System.currentTimeMillis();
		System.out.println("耗时"+(end-begin));
		return collection;
	}
	
	public static void main(String[] args){
		String[] test = {
				MovieGenerator.next(),
				MovieGenerator.next(),
				MovieGenerator.next(),
				MovieGenerator.next(),
				MovieGenerator.next(),
				MovieGenerator.next(),
				MovieGenerator.next(),
				MovieGenerator.next(),
				MovieGenerator.next(),
				MovieGenerator.next(),
				MovieGenerator.next(),
		};
		System.out.println(test);
		System.out.println(fill(new ArrayList<String>()));
		System.out.println(fill(new LinkedList<String>()));
		System.out.println(fill(new HashSet<String>()));
		System.out.println(fill(new LinkedHashSet<String>()));
		System.out.println(fill(new TreeSet<String>()));
	}
}

class MovieGenerator{
	private static String[] movies = {
			"泰坦尼克",
			"失恋三十三天",
			"黄金大劫案",
			"指环王",
			"星战",
			"十二怒汉",
			"不见不散",
			"马大帅",
			"北京爱情故事",
	};
	
	private static int size = movies.length;
	
	private static int i = 0;
	
	public static String next(){
		if (i >= size){
			i = 0;
		}
		return movies[i++];
	}
}